// Required Packages:
//   * Install-Package bootstrap.TypeScript.DefinitelyTyped

/// <reference path="DreamSpace.UI.ts"/>

module DreamSpace {

    /** Contains a series of Bootstrap controls wrapped in GraphItem derived classes. */
    export module Bootstrap {

        // ===================================================================================================================

        export enum ButtonTypes {
            /** Standard gray button with gradient. */
            Default = <ButtonTypes><any>"btn",
            /** Provides extra visual weight and identifies the primary action in a set of buttons. */
            Primary = <ButtonTypes><any>"btn btn-primary",
            /** Used as an alternative to the default styles. */
            Info = <ButtonTypes><any>"btn btn-info",
            /** Indicates a successful or positive action. */
            Success = <ButtonTypes><any>"btn btn-success",
            /** Indicates caution should be taken with this action. */
            Warning = <ButtonTypes><any>"btn btn-warning",
            /** Indicates a dangerous or potentially negative action. */
            Danger = <ButtonTypes><any>"btn btn-danger",
            /** Alternate dark gray button, not tied to a semantic action or use. */
            Inverse = <ButtonTypes><any>"btn btn-inverse",
            /** Deemphasize a button by making it look like a link while maintaining button behavior. */
            Link = <ButtonTypes><any>"btn btn-link"
        }

        export class ButtonSize {
            static Large: ButtonSize = "btn-large";
            static Default: ButtonSize = "";
            static Small: ButtonSize = "btn-small";
            static Mini: ButtonSize = "btn-mini";
        }

        export class RowStates {
            static Default: RowStates = "";
            static Success: RowStates = "success";
            static Error: RowStates = "error";
            static Warning: RowStates = "warning";
            static Info: RowStates = "info";
        }

        // ===================================================================================================================

        /** Represents a button type in Bootstrap. */
        export class Button extends GraphItem {

            // ---------------------------------------------------------------------------------------------------------------

            static __StaticConstructor = (() => { /*do static stuff :) */ })();

            static UIProperties: { ButtonType; ButtonSize; BLockLevel; IsDisabled; }
            = {
                ButtonType: "ButtonType",
                ButtonSize: "ButtonSize",
                BLockLevel: "BlockLevel",
                IsDisabled: "IsDisabled"
            };

            // private _buttonType: ButtonTypes;
            // ES5 ONLY; get buttonType(): ButtonTypes { return _buttonType; }
            // ES5 ONLY; set buttonType(value: ButtonTypes) { _buttonType = value; }

            buttonType: (buttonType?: ButtonTypes) => ButtonTypes = DreamSpace.GraphItem.accessor(Button.UIProperties.ButtonType);
            buttonSize: (buttonSize?: ButtonSize) => ButtonSize = DreamSpace.GraphItem.accessor(Button.UIProperties.ButtonSize);
            buttonLevel: (buttonLevel?: boolean) => boolean = DreamSpace.GraphItem.accessor(Button.UIProperties.BLockLevel);
            isDisabled: (isDisabled?: boolean) => boolean = DreamSpace.GraphItem.accessor(Button.UIProperties.IsDisabled);

            // ---------------------------------------------------------------------------------------------------------------

            constructor(parent: GraphItem, buttonType: ButtonTypes = ButtonTypes.Success, buttonSize: ButtonSize = ButtonSize.Default) {
                super(parent)
                this.buttonType(buttonType);
                this.buttonSize(buttonSize);
                this.htmlTag = "button";
            }

            // ---------------------------------------------------------------------------------------------------------------

            createUIElement(): Node {
                this.assertUnsupportedElementTypes("html", "head", "body", "script", "audio", "canvas", "object");
                return super.createUIElement();
            }

            // ---------------------------------------------------------------------------------------------------------------

            onRedraw(recursive: boolean = true) {
                super.onRedraw(recursive);
                this.setProperty("class", this.properties[Button.UIProperties.ButtonType]
                    + " " + this.properties[Button.UIProperties.ButtonSize]
                    + " " + (this.properties[Button.UIProperties.BLockLevel] ? "btn-block" : "")
                    + " " + (this.properties[Button.UIProperties.IsDisabled] ? "disabled" : "")
                    , false);
            }

            // ---------------------------------------------------------------------------------------------------------------
        }

        // ===================================================================================================================

        /** Represents a button type in Bootstrap. */
        export class Table extends GraphItem {

            // ---------------------------------------------------------------------------------------------------------------

            constructor(parent: GraphItem) {
                super(parent)
                this.htmlTag = "table";
            }

            // ---------------------------------------------------------------------------------------------------------------

            createUIElement(): Node {
                this.assertSupportedElementTypes("table");
                return super.createUIElement();
            }

            // ---------------------------------------------------------------------------------------------------------------

            onPropertyChanged(name: string, value: any) {
                if (name == "class")
                    this.onRedraw();
            }

            // ---------------------------------------------------------------------------------------------------------------

            onRedraw(recursive: boolean = true) {
                super.onRedraw(recursive);
                this.setProperty("class", "table", false);
            }

            // ---------------------------------------------------------------------------------------------------------------
        }

        // ===================================================================================================================

        /** Represents a row on a table type in Bootstrap. */
        export class TableRow extends DreamSpace.UI.TableRow {

            // ---------------------------------------------------------------------------------------------------------------

            static UIProperties: { RowState; }
            = {
                RowState: "RowState"
            };

            rowState: (rowState?: RowStates) => RowStates = DreamSpace.GraphItem.accessor(TableRow.UIProperties.RowState);

            // ---------------------------------------------------------------------------------------------------------------

            constructor(parent: GraphItem, rowState: RowStates = RowStates.Default) {
                super(parent)
                this.setProperty(TableRow.UIProperties.RowState, rowState);
            }

            // ---------------------------------------------------------------------------------------------------------------

            onRedraw(recursive: bool = true) {
                super.onRedraw(recursive);
                this.setProperty("class", this.properties[TableRow.UIProperties.RowState], false);
            }

            // ---------------------------------------------------------------------------------------------------------------
        }

        // ===================================================================================================================
    }

}
